<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://www.ccut.edu.cn/saturn" prefix="saturn"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Map"%>
<%@page import="edu.ccut.saturn.component.SaturnData"%>
<html>
<head>
<%@ include file="/jsp/include/header/meta.jsp"%>
<%@ include file="/jsp/include/header/stylesheettag.jsp"%>
<%@ include file="/jsp/include/header/javascript.jsp"%>
<script language="javaScript">

function bundleStart(key){
	insertOrganForm.action = "<%=request.getContextPath()%>/edu.ccut.saturn.manager.bundles.impl::/bundleModule/appBundleAction/InstallBundle.action?key="+key;
	insertOrganForm.submit();
}
function bundleStop(key){
	insertOrganForm.action = "<%=request.getContextPath()%>/edu.ccut.saturn.manager.bundles.impl::/bundleModule/appBundleAction/UninstallBundle.action?key="+key;
	insertOrganForm.submit();
}
function bundleInfo(key){
//	insertOrganForm.action = "<%=request.getContextPath()%>/saturnManager::/bundleModule/action/ObtainBundleInfoAction.action?key="+key;
//	insertOrganForm.submit();
//	insertOrganForm.action = "<%=request.getContextPath()%>/edu.ccut.saturn.manager.bundles.impl::/componentVisualModule/treeAndGrapAction/GetBundleTreeXml.action?key="+key;
//	insertOrganForm.submit();

insertOrganForm.action = "<%=request.getContextPath()%>/edu.ccut.saturn.manager.bundles.impl::/componentModule/action/QueryBundleInfoAction.action?key="+key;
	insertOrganForm.submit();
	
}
</script>
<title>bundles管理</title>
</head>

<body>
<% 
	List bundleList = (List) request.getAttribute("bundleList"); 
	List sysBundleList = new ArrayList(); 
	List appBundleList = new ArrayList(); 
	
	for(int i=0;i<bundleList.size();i++){
		SaturnData bundleInfo = (SaturnData)bundleList.get(i);
		String bundleFilePath = bundleInfo.getString("bundleFilePath");
		
		if(bundleFilePath != null) {
			if(bundleFilePath.indexOf("\\plugins") != -1) {
				appBundleList.add(bundleInfo);
			}else if(bundleFilePath.indexOf("\\1") != -1 
					|| bundleFilePath.indexOf("\\2") != -1) {
				sysBundleList.add(bundleInfo);
		    }else if(bundleInfo.getString("key").equals("System Bundle")){
		    	sysBundleList.add(bundleInfo);
			}else{
				appBundleList.add(bundleInfo);
			}		
		}	
	}

	request.setAttribute("sysBundleList",sysBundleList);
	request.setAttribute("appBundleList",appBundleList);
%>
<saturn:formBeans name="sysBundlesForm" title="系统bundles" action="${pageContext.request.contextPath}/saturnManager::/bundleModule/action/InstallBundleAction.action" method="post">
	<td>
	<saturn:table id="sysBundleList" value="${sysBundleList}" 
		item="var" isCursor="true" isPagepilot="true" percount="6">
		<saturn:tableColumn title="名称">
		<!--
					<a href="javascript:bundleInfo('<saturn:out value="${var.symbolicName}"/>')"><saturn:out value="${var.key}"/></a>
		-->
		<saturn:out value="${var.key}"/>
		</saturn:tableColumn>
		<saturn:tableColumn title="标识">
					<saturn:out value="${var.symbolicName}"/>
		</saturn:tableColumn>
		<saturn:tableColumn title="版本">
					<saturn:out value="${var.version}"/>
		</saturn:tableColumn>
	</saturn:table>
	</td>
	</saturn:formBeans>
	<saturn:formBeans name="dictListForm" title="查询应用bundles"
		action="${pageContext.request.contextPath}/edu.ccut.saturn.manager.bundles.impl::/bundleModule/appBundleAction/QueryBundlesbyCondition.action"
		method="post">
		
		<saturn:formBean label="bundle名称" name="name" type="text"
			id="name" value=""/>
		<saturn:formBean label="bundle标识" name="key" type="text"
			id="key" value=""/>
		<saturn:formActions>
			<saturn:formAction id="query" name="query" value="查询" />
		</saturn:formActions>
		<saturn:formBeanLine/>
</saturn:formBeans>
	<saturn:formBeans name="insertOrganForm" title="应用bundles管理" action="${pageContext.request.contextPath}/edu.ccut.saturn.manager.bundles.impl::/appBundleAction/InstallBundle.action" method="post">
	<td>
		<saturn:table id="appBundleList" value="${appBundleList}" 
			item="var" isCursor="true" isPagepilot="true" percount="6">
			<saturn:tableColumn title="名称">
						<a href="javascript:bundleInfo('<saturn:out value="${var.symbolicName}"/>')"><saturn:out value="${var.key}"/></a>
			</saturn:tableColumn>
			<saturn:tableColumn title="标识">
						<saturn:out value="${var.symbolicName}"/>
			</saturn:tableColumn>
			<saturn:tableColumn title="版本">
						<saturn:out value="${var.version}"/>
			</saturn:tableColumn>
			<saturn:tableColumn title="操作">
			<%	
			SaturnData bundleInfo = (SaturnData)pageContext.getAttribute("var");
			if(bundleInfo != null){
			if(bundleInfo.getString("status").equals("enable")){ %>
				<a href="#" disabled>启动</a>
				|<a href="#" onclick="bundleStop('<saturn:out value="${var.symbolicName}"/>')">停止</a>
			<% }else{ %>
			<a href="#" onclick="bundleStart('<saturn:out value="${var.symbolicName}"/>')">启动</a>
			|<a href="#" disabled>停止</a>
			<% }%>
			<% }%>	
			</saturn:tableColumn>
		</saturn:table>
	</td>
	</saturn:formBeans>                                                                                                
	<saturn:formBeans name="upLoadForm" title="上传bundles管理" action="${pageContext.request.contextPath}/edu.ccut.saturn.manager.bundles.impl::/bundleModule/releaseAction/ReleaseBundle.action?symbolicName=bnnnnn&versionNum=1.0.0" method="post" >
		<table>
			<tr>
			<td>
				选择bundle :<input type="file" name="file"/>
				</td>
			</tr>
			<tr>
			<td>
				<input type="submit" value="上传" name="upload"/>
				</td>
			</tr>
		</table>
	</saturn:formBeans>

</body>
</html>